import Base from './Base'
import Page from './Page'

class ProductNetvalue extends Base {
  constructor ({
    id = '',
    product = {id: '', name: ''},
    unitNetvalue = '',
    totalUnitNetvalue = '',
    newestDate = ''
  }) {
    super({id})

    this.product = product
    this.unitNetvalue = unitNetvalue
    this.totalUnitNetvalue = totalUnitNetvalue
    this.newestDate = newestDate
  }
  // 获取净值分页列表
  static async find (params) {
    let {content, ...pagination} = await ProductNetvalue.$http.get(`${ProductNetvalue.$name}/listByProductId`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
  // 获取所有净值
  static async findAll (params) {
    let res = await ProductNetvalue.$http.get(`${ProductNetvalue.$name}/list/${params.productId}`, {params})
    return res
  }
  // 获取所有类型的最新净值分页列表
  static async findNew (params) {
    let {content, ...pagination} = await ProductNetvalue.$http.get(`${ProductNetvalue.$name}/newest`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
}
// 静态属性
ProductNetvalue.$name = '/product/netvalue'
export default ProductNetvalue
